let currenId = ''
Page({
  data: {
    dialogVisible: false,
  },
  onShow() {
    this.getHouseList()
  },
  // 发送请求
  async getHouseList() {
    const {
      code,
      data: houseList
    } = await wx.$http.get('/room')
    if (code !== 10000) return wx.$utilss.toast('房屋响应失败')
    console.log(houseList)
    this.setData({
      houseList,
    })
  },
  /*   onLoad() {
      // 获取全局页面的token 用于做页面路由跳转
      console.log('我的房屋:', getApp().token);
      if (!getApp().token) {
        wx.redirectTo({
          url: '/pages/login/index',
        })
      }
    }, */
  swipeClose(ev) {
    console.log(ev);
    currenId = ev.mark.id
    const {
      position,
      instance
    } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },
  // 点击右侧滑动 删除按钮
  async dialogClose(e) {
    console.log(e)
    if (e.detail === confirm) {
      // 发送请求
      const res = await wx.$http.delete(`/room/${currenId}`)
      if (res.code !== 10000) return wx.$utilss.toast('房屋删除失败')
      this.getHouseList()
    }
  },
  // 点击房屋列表 进入编辑页面
  goDetail(e) {
    console.log(e);
    // 把id传递到页面中去
    wx.navigateTo({
      url: `/house_pkg/pages/detail/index?id=${e.mark.id}`,
    })
  },
  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})